<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>StellarDrift - 创建瓶子页原型</title>
    <style>
        @import url('https://fonts.googleapis.com/css2?family=Noto+Sans+SC:wght@300;400;500&display=swap');

        :root {
            --phone-width: 430px;
            --phone-height: 932px;
            --primary-bg: #0D1B2A;
            --secondary-bg: #1B263B;
            --lighter-bg: #415A77;
            --paper-bg: #FDFDF0;
            --accent-gold: #FFD700;
            --text-light: #E0E1DD;
            --text-dark: #778DA9;
            --text-on-paper: #333;
        }

        body {
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
            background-color: #f0f2f5;
            font-family: 'Noto Sans SC', sans-serif;
            overflow: hidden;
        }

        .phone-shell {
            width: var(--phone-width);
            height: var(--phone-height);
            background-color: #111;
            border-radius: 50px;
            padding: 12px;
            box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3), 0 0 0 10px #000;
            position: relative;
        }

        .screen {
            width: 100%;
            height: 100%;
            background-color: var(--primary-bg); /* Base color */
            border-radius: 40px;
            position: relative;
            overflow: hidden;
            display: flex;
            flex-direction: column;
        }

        /* Mockup Elements */
        .notch {
            position: absolute;
            top: 12px;
            left: 50%;
            transform: translateX(-50%);
            width: 140px;
            height: 35px;
            background-color: #111;
            border-radius: 0 0 20px 20px;
            z-index: 100;
        }
        .home-indicator {
            position: absolute;
            bottom: 10px;
            left: 50%;
            transform: translateX(-50%);
            width: 140px;
            height: 5px;
            background-color: rgba(255, 255, 255, 0.4);
            border-radius: 5px;
            z-index: 100;
        }
        
        /* Main App Page (BottomSheet simulation) */
        .create-bottle-page {
            position: absolute;
            bottom: 0;
            left: 0;
            width: 100%;
            height: 95%; 
            background-color: var(--lighter-bg);
            border-radius: 30px 30px 0 0;
            box-shadow: 0 -10px 30px rgba(0,0,0,0.3);
            display: flex;
            flex-direction: column;
            padding: 20px;
            box-sizing: border-box;
            color: var(--text-light);
            animation: slide-up 0.5s ease-out forwards;
            z-index: 50;
        }
        
        @keyframes slide-up {
            from { transform: translateY(100%); }
            to { transform: translateY(0); }
        }

        .page-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 20px;
            flex-shrink: 0;
        }

        .header-title {
            font-size: 18px;
            font-weight: 500;
        }

        .post-button {
            background-color: var(--accent-gold);
            color: var(--primary-bg);
            border: none;
            padding: 8px 20px;
            border-radius: 20px;
            font-weight: 500;
            cursor: pointer;
            transition: opacity 0.3s ease, transform 0.2s ease;
        }
        .post-button:disabled {
            background-color: var(--text-dark);
            color: #aaa;
            cursor: not-allowed;
            opacity: 0.7;
        }
        .post-button:not(:disabled):active {
            transform: scale(0.95);
        }

        .bottle-type-selector {
            display: flex;
            gap: 15px;
            margin-bottom: 20px;
            flex-shrink: 0;
        }

        .type-card {
            flex: 1;
            padding: 15px;
            border: 2px solid var(--text-dark);
            border-radius: 12px;
            text-align: center;
            cursor: pointer;
            transition: all 0.3s ease;
        }
        .type-card.active {
            border-color: var(--accent-gold);
            background-color: rgba(255, 215, 0, 0.1);
            transform: translateY(-2px);
            box-shadow: 0 4px 10px rgba(255, 215, 0, 0.2);
        }
        .type-card-title {
            font-size: 16px;
            font-weight: 500;
            margin-bottom: 5px;
        }
        .type-card-desc {
            font-size: 12px;
            color: var(--text-light);
            opacity: 0.8;
        }

        .options-container {
            margin-bottom: 20px;
            min-height: 50px; /* Reserve space to prevent layout shift */
            flex-shrink: 0;
        }

        .option-item {
            display: none; /* Hidden by default */
            justify-content: space-between;
            align-items: center;
            padding: 10px;
            background-color: rgba(0,0,0,0.2);
            border-radius: 8px;
        }
        .option-item.visible {
            display: flex;
        }
        
        /* Custom styled switch */
        .switch {
            position: relative;
            display: inline-block;
            width: 50px;
            height: 28px;
        }
        .switch input { display: none; }
        .slider {
            position: absolute;
            cursor: pointer;
            top: 0; left: 0; right: 0; bottom: 0;
            background-color: var(--text-dark);
            transition: .4s;
            border-radius: 28px;
        }
        .slider:before {
            position: absolute;
            content: "";
            height: 20px;
            width: 20px;
            left: 4px;
            bottom: 4px;
            background-color: white;
            transition: .4s;
            border-radius: 50%;
        }
        input:checked + .slider {
            background-color: var(--accent-gold);
        }
        input:checked + .slider:before {
            transform: translateX(22px);
        }
        
        input[type="datetime-local"] {
            background-color: transparent;
            border: none;
            color: var(--text-light);
            font-family: 'Noto Sans SC', sans-serif;
            font-size: 16px;
        }
        input[type="datetime-local"]::-webkit-calendar-picker-indicator {
            filter: invert(1);
        }
        
        .content-editor {
            flex: 1;
            display: flex;
            flex-direction: column;
            background-color: var(--paper-bg);
            border-radius: 12px;
            padding: 15px;
            box-shadow: inset 0 2px 5px rgba(0,0,0,0.1);
        }
        
        .text-area {
            flex: 1;
            width: 100%;
            background-color: transparent;
            border: none;
            resize: none;
            font-size: 16px;
            line-height: 1.8;
            color: var(--text-on-paper);
            font-family: 'Kaiti SC', 'STKaiti', 'KaiTi', sans-serif; /* More like handwriting */
        }
        .text-area:focus {
            outline: none;
        }

        .char-counter {
            text-align: right;
            font-size: 12px;
            color: var(--text-dark);
            margin-top: 10px;
        }
        
        .success-overlay {
            position: absolute;
            top: 0; left: 0;
            width: 100%; height: 100%;
            background-color: var(--lighter-bg);
            z-index: 200;
            display: flex;
            justify-content: center;
            align-items: center;
            color: var(--accent-gold);
            font-size: 24px;
            font-weight: 500;
            opacity: 0;
            pointer-events: none;
            transition: opacity 0.5s ease;
        }
        .success-overlay.visible {
            opacity: 1;
        }

    </style>
</head>
<body>

    <div class="phone-shell">
        <div class="screen">
            <!-- Background from previous page, can be a static gradient -->
            <div style="width:100%; height:100%; background: linear-gradient(180deg, var(--primary-bg) 0%, var(--secondary-bg) 100%);"></div>

            <div class="notch"></div>
            
            <div class="create-bottle-page">
                <div class="page-header">
                    <span class="header-title">写下你的心事</span>
                    <button class="post-button" id="postButton" disabled>投递</button>
                </div>

                <div class="bottle-type-selector" id="bottleTypeSelector">
                    <div class="type-card" data-type="public">
                        <div class="type-card-title">公开漂流瓶</div>
                        <div class="type-card-desc">投给陌生的有缘人</div>
                    </div>
                    <div class="type-card" data-type="private">
                        <div class="type-card-title">时光瓶</div>
                        <div class="type-card-desc">写给未来的自己</div>
                    </div>
                </div>
                
                <div class="options-container">
                    <div class="option-item" id="anonymousOption">
                        <span>匿名投递</span>
                        <label class="switch">
                            <input type="checkbox">
                            <span class="slider"></span>
                        </label>
                    </div>
                    <div class="option-item" id="timeOption">
                        <span>开启时间</span>
                        <input type="datetime-local" id="timePicker">
                    </div>
                </div>

                <div class="content-editor">
                    <textarea class="text-area" id="bottleContent" placeholder="在这里输入你的故事..." maxlength="1000"></textarea>
                    <div class="char-counter" id="charCounter">0 / 1000</div>
                </div>
            </div>

            <div class="success-overlay" id="successOverlay">
                瓶子已成功投出！
            </div>

            <div class="home-indicator"></div>
        </div>
    </div>

<script>
document.addEventListener('DOMContentLoaded', function() {
    const bottleTypeSelector = document.getElementById('bottleTypeSelector');
    const anonymousOption = document.getElementById('anonymousOption');
    const timeOption = document.getElementById('timeOption');
    const timePicker = document.getElementById('timePicker');
    const bottleContent = document.getElementById('bottleContent');
    const charCounter = document.getElementById('charCounter');
    const postButton = document.getElementById('postButton');
    const successOverlay = document.getElementById('successOverlay');

    let selectedType = null;

    function validateForm() {
        const isContentValid = bottleContent.value.trim().length > 0;
        let isTypeValid = false;

        if (selectedType === 'public') {
            isTypeValid = true;
        } else if (selectedType === 'private') {
            isTypeValid = timePicker.value !== '';
            // Optional: More robust date validation
            if (isTypeValid) {
                const selectedDate = new Date(timePicker.value);
                const now = new Date();
                if (selectedDate <= now) {
                    isTypeValid = false;
                }
            }
        }
        
        postButton.disabled = !(isContentValid && isTypeValid);
    }
    
    // Set min date for time picker to tomorrow
    function setMinTime() {
        const now = new Date();
        now.setDate(now.getDate() + 1); // At least 1 day in the future
        const year = now.getFullYear();
        const month = (now.getMonth() + 1).toString().padStart(2, '0');
        const day = now.getDate().toString().padStart(2, '0');
        const hours = now.getHours().toString().padStart(2, '0');
        const minutes = now.getMinutes().toString().padStart(2, '0');
        timePicker.min = `${year}-${month}-${day}T${hours}:${minutes}`;
    }

    bottleTypeSelector.addEventListener('click', (event) => {
        const card = event.target.closest('.type-card');
        if (!card) return;

        // Reset previous active state
        const currentActive = bottleTypeSelector.querySelector('.active');
        if (currentActive) {
            currentActive.classList.remove('active');
        }

        // Set new active state
        card.classList.add('active');
        selectedType = card.dataset.type;

        // Show/hide options
        if (selectedType === 'public') {
            anonymousOption.classList.add('visible');
            timeOption.classList.remove('visible');
        } else if (selectedType === 'private') {
            anonymousOption.classList.remove('visible');
            timeOption.classList.add('visible');
        }
        
        validateForm();
    });

    bottleContent.addEventListener('input', () => {
        const count = bottleContent.value.length;
        charCounter.textContent = `${count} / 1000`;
        validateForm();
    });
    
    timePicker.addEventListener('change', validateForm);

    postButton.addEventListener('click', () => {
        if (postButton.disabled) return;
        
        console.log('投递瓶子:', {
            type: selectedType,
            content: bottleContent.value,
            isAnonymous: selectedType === 'public' ? document.querySelector('#anonymousOption input').checked : null,
            openTime: selectedType === 'private' ? timePicker.value : null,
        });
        
        // Show success animation
        document.querySelector('.create-bottle-page').style.transition = 'opacity 0.5s ease';
        document.querySelector('.create-bottle-page').style.opacity = '0';
        successOverlay.classList.add('visible');
        
        // Simulate closing the page after a delay
        setTimeout(() => {
            // alert("返回主界面 (模拟)");
            // In a real app, this would navigate back.
            // For prototype, we can reload or hide the element.
            window.location.href = 'HomePage.html'; 
        }, 2000);
    });

    // Initialize
    setMinTime();
    validateForm();
});
</script>

</body>
</html> 